import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;

public class JAPI_Mouselistener implements MouseListener
{

//  Varaibles

	JAPI_SocketOutputStream JAPI_actionstream;
	int JAPI_id;		
	int JAPI_x=0;
	int JAPI_y=0;
	int JAPI_event;
	int debuglevel=0;
	int button=InputEvent.BUTTON1_MASK;	
	
//  own Methods
	public JAPI_Mouselistener(int object_id, JAPI_SocketOutputStream action , int event) 
	throws IOException
	{
		JAPI_actionstream=action;
		JAPI_id = object_id;		
		JAPI_event=event;
	}
	
	public int getxpos()
	{
		return(JAPI_x);
	} 

	public int getypos()
	{
		return(JAPI_y);
	} 

	public int getbutton()
	{
		return(button);
	} 

	public void mousePressed(MouseEvent e)
	{
		if(JAPI_event == JAPI_Const.J_PRESSED)
		{
			if(debuglevel > 1) System.out.println("Mouse Event Pressed "+this.JAPI_id);	
			JAPI_x = e.getX();
			JAPI_y = e.getY();
			button = e.getModifiers();
			try
			{	
				JAPI_actionstream.sendInt(JAPI_id);
			}	
			catch(IOException exce) {}		
		}
	}
	public void mouseReleased(MouseEvent e)
	{
		if(JAPI_event == JAPI_Const.J_RELEASED)
		{
			if(debuglevel > 1) System.out.println("Mouse Event Released "+this.JAPI_id);		
			JAPI_x = e.getX();
			JAPI_y = e.getY();
			button = e.getModifiers();
			try
			{	
				JAPI_actionstream.sendInt(JAPI_id);
			}	
			catch(IOException exce) {}		
		}
	}

	public void mouseEntered(MouseEvent e)
	{
		if(JAPI_event == JAPI_Const.J_ENTERERD)
		{
			if(debuglevel > 1) System.out.println("Mouse Event Entered "+this.JAPI_id);		
			JAPI_x = e.getX();
			JAPI_y = e.getY();
			button = e.getModifiers();
			try
			{	
				JAPI_actionstream.sendInt(JAPI_id);
			}	
			catch(IOException exce) {}		
		}
	}
	
	public void mouseExited(MouseEvent e)
	{
		if(JAPI_event == JAPI_Const.J_EXITED)
		{
			if(debuglevel > 1) System.out.println("Mouse Event Exit "+this.JAPI_id);		
			JAPI_x = e.getX();
			JAPI_y = e.getY();
			button = e.getModifiers();
			try
			{	
				JAPI_actionstream.sendInt(JAPI_id);
			}	
			catch(IOException exce) {}		
		}
	}

	
	public void mouseClicked(MouseEvent e)
	{
		if((JAPI_event == JAPI_Const.J_DOUBLECLICK) && (e.getClickCount()==2))
		{
			if(debuglevel > 1) System.out.println("Mouse Double Click "+this.JAPI_id);		
			JAPI_x = e.getX();
			JAPI_y = e.getY();
			button = e.getModifiers();
			try
			{	
				JAPI_actionstream.sendInt(JAPI_id);
			}	
			catch(IOException exce) {}		
		}
	}
	
	public void setdebuglevel(int level)
	{
		debuglevel=level;
	}
}